XML is a versatile markup language, capable of labeling the information content of diverse data sources including structured and semi-structured documents, relational databases, and object repositories. A query language that uses the structure of XML intelligently can express queries across all these kinds of data, whether physically stored in XML or viewed as XML via middleware. As increasing amounts of information are stored, exchanged, and presented using XML, the ability to query XML data sources intelligently becomes increasingly important. One of the great strengths of XML is its flexibility in representing many different kinds of information from diverse sources. To exploit this flexibility, an XML query language should provide features for retrieving and interpreting information from these diverse sources.
The XQuery query language is designed to query collections of XML data. XQuery is semantically similar to SQL. XQuery 1.0 was developed by the XML Query working group of the W3C. XQuery 1.0 became a W3C Recommendation on Jan. 23, 2007 and is described in http://www.w3.org/TR/xquery/. The contents of the Recommendation are incorporated by this reference for all purposes as if fully disclosed herein. XQuery is designed to be a language in which queries are concise and easily understood. XQuery is also flexible enough to query a broad spectrum of XML information sources, including both databases and documents. XQuery operates on the abstract, logical structure (i.e., the data model) of an XML document, rather than its surface syntax. An XQuery expression may comprise multiple expressions (i.e., sub-expressions).
SQL/XML is a query language that is an extension to the SQL standard. SQL/XML is defined by ISO/IEC 9075-14:2003 and specifies SQL-based extensions for using XML in conjunction with SQL. SQL/XML introduces the XML data type, as well as several routines, functions, and XML-to-SQL data type mappings to support manipulation and storage of XML in a database that supports SQL.
XQuery and SQL/XML share many common concepts and constructs, such as join, predicates, an order-by clause, and projection. For example, projection in XQuery is specified by a return clause and projection in SQL/XML is specified in a select clause.
Currently, SQL/XML engines, such as the SQL/XML engine provided by Oracle 10 g, have been developed and optimized to process (e.g., rewrite) SQL/XML queries in order to generate efficient execution plans. For example, an SQL/XML engine might determine that an XML index may be used to execute a portion of an SQL/XML query and, accordingly, rewrite the query to specify the XML index. Therefore, the fact that XQuery and SQL/XML share many common constructs facilitates rewriting XQuery constructs into SQL/XML constructs.
The following query is an example XQuery query:
for $i in ora:view(“Tab”)where $i/PurchaseOrder/PONumber = 45orderby $i/PurchaseOrder/PODatereturn <newPO> {$i/PurchaseOrder/POItem} </newPO>where ora:view(“Tab”) returns table “Tab” that contains Purchase Order documents and where “PO” is shorthand for “PurchaseOrder.” The above XQuery query may be rewritten into the following SQL/XML query:
select XQextract(“newPO”, value(t), ‘/PurchaseOrder/POItem’)from Tab twhere XQgetValue(value(t), ‘/PurchaseOrder/PONumber’) = 45orderby XQgetValue(value(t), ‘/PurchaseOrder/PODate’)The XQextract( ) operator returns a copy of the node “/PurchaseOrder/POItem” and surrounds the copy with the tag “<newPO>.” Because XQuery queries can be rewritten to SQL/XML queries, XQuery queries can take advantage (indirectly) of existing SQL/XML engines.
However, SQL/XML engines are essentially value-based systems and some XQuery queries are referenced-based. Some XQuery constructs, such as node comparison operators, operate on a tree-based data model where each node in an XQuery data model sequence is semantically a reference to a node of the tree. Examples of node operators include IS, <<, >>, UNION, INTERSECT, and EXCEPT.
Currently, SQL/XML engines do not rewrite XQuery queries that rely on node reference semantics. Thus, XQuery queries that involve node identity comparisons, such as IS, <<, >>, UNION, INTERSECT, and EXCEPT, must be processed by a coprocessor outside of the SQL/XML engine and, thus, cannot take advantage of SQL/XML engines.
The approaches described in this section are approaches that could be pursued, but not necessarily approaches that have been previously conceived or pursued. Therefore, unless otherwise indicated, it should not be assumed that any of the approaches described in this section qualify as prior art merely by virtue of their inclusion in this section.